package com.ch.home.service.serviceImpl.restDishServiceImpl;

import com.ch.home.bean.DishCustom;
import com.ch.home.mapper.restDishMapper.DishCustomMapper;
import com.ch.home.service.serviceInterface.restDishService.DishCustomService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.HashMap;
import java.util.LinkedList;

/**
 * Created by CHEN on 2019/8/27.
 */
@Service
public class DishCustomServiceImpl implements DishCustomService {


    @Autowired
    DishCustomMapper dishCustomMapper;


    @Override
    public HashMap getPreview(DishCustom dishCustom) {
        return null;
    }

    @Override
    public HashMap getAll(DishCustom dishCustom) {
        HashMap<Object, Object> result = new HashMap<>( );
        LinkedList<DishCustom> dishCustomAndSource = dishCustomMapper.getDishCustomAndSource(dishCustom);

        if (dishCustomAndSource.size( ) > 0) {
            result.put("message", "success");
        } else {
            result.put("message", "fail");
        }

        result.put("value", dishCustomAndSource);
        return result;
    }

    @Override
    public HashMap add(DishCustom dishCustom) {
        HashMap<Object, Object> result = new HashMap<>( );

        int re = dishCustomMapper.addDishCustom(dishCustom);
        if (re == 1) {
            result.put("message", "success");
        } else {
            result.put("message", "fail");
        }
        return result;
    }


    @Override
    public HashMap update(DishCustom dishCustom) {
        HashMap<Object, Object> result = new HashMap<>( );

        int re = dishCustomMapper.updateDishCustom( dishCustom);
        if (re == 1) {

            result.put("message", "success");
        } else {
            result.put("message", "fail");
        }
        return result;

    }
}
